mod mysql;
mod sqlite;

use model_graph_types::{
    database::{DataSource, DatabaseType},
    extractor::{DataExtractor, DataValueSet, ExtractByClassFromDatabaseOption, PageInfor},
    modeling::{Class, Value},
};

pub struct DefaultDataExtractor {}

#[async_trait::async_trait]
impl DataExtractor for DefaultDataExtractor {
    /// 根据数据库获取到元数据
    async fn extract_by_class_from_database(
        &self,
        class: &Class,
        data_source: &DataSource,
        options: ExtractByClassFromDatabaseOption,
    ) -> anyhow::Result<DataValueSet<Class, PageInfor>> {
        match data_source.database_type {
            DatabaseType::SQLite => {
                sqlite::by_class::extract_by_class_from_database(class, data_source, options).await
            }
            DatabaseType::MySQL => {
                mysql::by_class::extract_by_class_from_database(class, data_source, options).await
            }
            _ => Err(anyhow::anyhow!("不支持的数据类型")),
        }
    }
}
